/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package jpa.entities;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;

/**
 *
 * @author andreas
 */
@Entity
@Table(name = "BANKAPP_USER")
@NamedQueries({
    @NamedQuery(name = "User.findAll", query = "SELECT b FROM User b"),
    @NamedQuery(name = "User.findByUserid", query = "SELECT b FROM User b WHERE b.userid = :userid"),
    @NamedQuery(name = "User.findByPassword", query = "SELECT b FROM User b WHERE b.password = :password")})
public class User implements Serializable {
        
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Basic(optional = false)
    @Column(name = "USERID", nullable = false)
    @Min(100000)
    @Max(999999)
    private Integer userid;
    @Basic(optional = false)
    @Column(name = "PASSWORD")
    @Min(100000)
    @Max(999999)
    private Integer password;
    @JoinTable(name = "BANKAPP_USER_USERGROUP", joinColumns = {
        @JoinColumn(name = "USERID", referencedColumnName = "USERID", nullable = false)}, inverseJoinColumns = {
        @JoinColumn(name = "USERGROUPNAME", referencedColumnName = "NAME", nullable = false)})
    @ManyToMany
    private Set<UserGroup> usergroups = new HashSet<UserGroup>();

    public Integer getPassword() {
        return password;
    }

    public void setPassword(Integer password) {
        this.password = password;
    }

    public Set<UserGroup> getUsergroups() {
        return usergroups;
    }

    public void setUsergroups(Set<UserGroup> usergroups) {
        this.usergroups = usergroups;
    }

    public Integer getUserid() {
        return userid;
    }

    public void setUserid(Integer userid) {
        this.userid = userid;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final User other = (User) obj;
        if (this.userid != other.userid && (this.userid == null || !this.userid.equals(other.userid))) {
            return false;
        }
        if (this.password != other.password && (this.password == null || !this.password.equals(other.password))) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 53 * hash + (this.userid != null ? this.userid.hashCode() : 0);
        hash = 53 * hash + (this.password != null ? this.password.hashCode() : 0);
        return hash;
    }

    @Override
    public String toString() {
        return "User{" + "userid=" + userid + '}';
    }

}
